package com.peachcastle.core
{
	import com.peachcastle.tools.DToolTip;
	import com.peachcastle.tools.Utils;
	import flash.display.DisplayObjectContainer;
	import flash.display.MovieClip;
	import flash.events.EventDispatcher;
	import flash.geom.Point;
	import flash.system.ApplicationDomain;
	
	/**
	 * ...
	 * @author Terry
	 */
	public class Display extends EventDispatcher 
	{
		
		private var _assest:MovieClip = null;
		
		private var _width:Number = 0;
		
		private var _height:Number = 0;
		
		private var _rotation:Number = 0;
		
		private var _x:Number = 0;
		
		private var _y:Number = 0;
		
		private var _position:Point = null;
		
		
		private var _parent:DisplayObjectContainer = null;//父级;
		
		private var _remove:Boolean = false;
		
		private var _show:Boolean = true;
		
		public function Display(ui:MovieClip = null,remove:Boolean = false) 
		{
			_assest = ui;
			_remove = remove;
			
			initialization();
			configEventListeners();
		}
		
		/**
		 * 初始化
		 */
		protected function initialization():void
		{
			if (!assest)
			{
				return;
			}
			assest.stop();
			assest.cacheAsBitmap = true;
		
			
			_parent = assest.parent;
			
			_x = assest.x;
			_y = assest.y;
			
			_position = new Point(assest.x, assest.y);
			
			_width = assest.width;
			_height = assest.height;
			
			_rotation = assest.rotation;
			
			if(_remove) hideAssest();
		}
		/**
		 * 注册事件
		 */
		protected function configEventListeners():void
		{
			
		}
		
		public function setToolTip(message:String = "",dic:String = ""):void
		{
			DToolTip.register(assest, message, dic);
		}
		
		public function showAssest():void
		{
			if (_show) return;
			_show = true;
			
			assest.x = _position.x;
			assest.y = _position.y;
			
			if (assest&&parent) parent.addChild(assest);
		}
		
		
		public function showAssestBase():void
		{
			if (_show) return;
			_show = true;
			
			assest.x = _position.x;
			assest.y = _position.y;
			
			if (assest&&parent) parent.addChildAt(assest, 0);
		}
		
		public function hideAssest():void
		{
			_show = false;
			if (assest && assest.parent) 
			{
				assest.parent.removeChild(assest);
			}
		}
		
		public function getNameByClass(name:String):Class
		{
			if (!ApplicationDomain.currentDomain.hasDefinition(name)) return null;
			
			return ApplicationDomain.currentDomain.getDefinition(name) as Class;
		}
		
		/**
		 * UI
		 */
		public function get assest():MovieClip { return _assest; }
		
		public function get x():Number { return _x; }
		public function set x(value:Number):void { assest.x = value; }
		public function set y(value:Number):void { assest.y = value; }
		public function get y():Number { return _y; }
		
		
		public function get width():Number { return _width; }
		public function get height():Number { return _height; }
		public function get rotation():Number { return _assest.rotation; }
		
		public function get parent():DisplayObjectContainer { return _parent; }
		
		public function get visible():Boolean { return _assest.visible; }
		public function set visible(value:Boolean):void { _assest.visible = value; }
		
		public function get alpha():Number { return _assest.alpha; }
		public function set alpha(value:Number):void { _assest.alpha = value; }
		
		public function set rotation(value:Number):void { _assest.rotation = value; }
	}

}